package cn.chrilwe.pigpig.im.counter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 *  房间在线人数计数器
 * @author chrilwe
 * 2020-8-21
 */
@Component
public class RoomOnlineUserCounter {
	
	private static final String ROOM_COUNTER = "ROOM_COUNTER_";
	
	@Autowired
	private StringRedisTemplate stringRedisTemplate;

	public void incr(String roomId) {
		stringRedisTemplate.opsForValue().increment(ROOM_COUNTER+roomId, 1l);
	}

	public void decr(String roomId) {
		stringRedisTemplate.opsForValue().increment(ROOM_COUNTER+roomId, -1l);
	}
}
